﻿#include "Mapper_Test_RTT.h"

#include "DataBaseConnector.h"
#include "MapperTool.h"

#include <qdatetime.h>
#include <qvariant.h>
#include <qsqlquery.h>
#include <qsqlerror.h>

#include <qdebug.h>

Mapper_Test_RTT::Mapper_Test_RTT()
{

}

Mapper_Test_RTT::~Mapper_Test_RTT()
{

}

void Mapper_Test_RTT::record(ushort msgId, ushort rtt, int interval, int bw, int rtt_ave, int rto, int bw_max)
{
  QString mysql="INSERT INTO "+string_dataBaseName+
                "("+string_msgId+","
                   +string_rtt+","
                   +"`"+string_interval+"`"+","
                   +string_now+","
                   +string_bw+","
                   +string_rtt_ave+","
                   +string_rto+","
                   +string_bw_max+")"+
                " VALUES "+"("+QString::number((uint)msgId)+","
                              +QString::number((uint)rtt)+","
                              +QString::number(interval)+","
                              +"'"+MapperTool::mysqlDateTimeString(QDateTime::currentDateTime())+"'"+","
                              +QString::number(bw)+","
                              +QString::number(rtt_ave)+","
                              +QString::number(rto)+","
                              +QString::number(bw_max)+")"+";";
  QSqlQuery query=dataBaseConnector->exec(mysql);
}

DataBaseConnector* Mapper_Test_RTT::getDataBaseConnector() const
{
  return dataBaseConnector;
}

Mapper_Test_RTT *Mapper_Test_RTT::setDataBaseConnector(DataBaseConnector * const dataBaseConnector)
{
  this->dataBaseConnector=dataBaseConnector;
  printInjection(this,dataBaseConnector);
  return this;
}

void Mapper_Test_RTT::objectAutoInjection(QHash<QString, QObject *> *objMap)
{
  setDataBaseConnector(getObjFromMap<DataBaseConnector>(objMap));
}
